import 'dart:async';
import 'package:flutter/material.dart';
import 'package:rc_app/contants/constant.dart';
import 'package:rc_app/pages/container_page.dart';
import 'package:rc_app/utils/screen_utils.dart';
class SplashWidget extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _SplashState();
  }
}
class _SplashState extends State<SplashWidget>{
  Widget containerPage = ContainerPage();
  int _seconds = 3;
  Timer _timer;
  bool showSplash = true;
  /// 启动倒计时的计时器。
  void _startTimer() {
    _timer = Timer.periodic(Duration(seconds: 1), (timer) {
      setState(() {});
      if (_seconds <= 1) {
        print('init container page');
        _cancelTimer();
        setState(() {
          showSplash = false;
        });
        return;
      }
      _seconds--;
    });
  }

  /// 取消倒计时的计时器。
  void _cancelTimer() {
    _timer?.cancel();
  }
  @override
  void initState() {
    super.initState();
    _startTimer();
  }
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Offstage(
          offstage: showSplash,
          child: containerPage,
        ),
        Offstage(
          offstage: !showSplash,
          child: Container(
            color: Colors.white,
            child: Image.asset(Constant.ASSETS_IMG+"splash.png",
              fit: BoxFit.cover,
              width: ScreenUtils.screenW(context),
              height: ScreenUtils.screenH(context),
            ),
          ),
        )
      ],
    );
  }
}